package encaps.action;

import encaps.entities.Grant;
import encaps.resources.Labels;

public class CreateMovieAction extends ApplyMovieChangesAction {

    public static final String CREATE_MOVIE = "createMovie";

    //protected ActionContext actionContext;
    public CreateMovieAction(ActionContext context, Grant requiredGrant) {
        super(context, requiredGrant);
        successActionMessage = Labels.getLabel(Labels.MOVIE_CREATED_MESSAGE);
        edit = true;
        //this.actionContext = context;
        //this.requiredGrant = requiredGrant;
    }

    /*
     * @Override public Element execute() throws ActionExecutionException {
     * String username = actionContext.getUserLogin(); return
     * XMLHelper.toXMLElement(new DefaultMovieFields(),
     * Labels.getLabel(Labels.CREATE_MOVIE), true, username);
    }
     */
    /*
     * @Override public Element execute() throws ActionExecutionException { try
     * { MovieLocalHome movieHome = EntityUtil.getMovieHome(); MovieLocal movie;
     * id = new Long(actionContext.getTextParameter(ID));
     *
     * String title= actionContext.getTextParameter(MOVIE_TITLE); String
     * descript = actionContext.getTextParameter(MOVIE_DESCRIPTION); String
     * length= actionContext.getTextParameter(MOVIE_LENGTH); String countries =
     * actionContext.getTextParameter(MOVIE_COUNTRIES); String
     * russianReleaseDate =
     * actionContext.getTextParameter(MOVIE_RUSRELEASEDATE); String
     * worldReleaseDate = actionContext.getTextParameter(MOVIE_WLDRELEASEDATE);
     * String studio = actionContext.getTextParameter(MOVIE_STUDIO); String
     * budget = actionContext.getTextParameter(MOVIE_BUDGET); String worldCash =
     * actionContext.getTextParameter(MOVIE_CASH); String genres =
     * actionContext.getTextParameter(MOVIE_GENRES); String picture =
     * actionContext.getTextParameter(MOVIE_PICTURE); persons_actors =
     * actionContext.getTextParameter(MOVIE_PERSONS_ACTORS); persons_directors =
     * actionContext.getTextParameter(MOVIE_PERSONS_DIRECTORS);
     * persons_producers =
     * actionContext.getTextParameter(MOVIE_PERSONS_PRODUCERS); Element
     * dataToReEnter = validateMovie(); if(dataToReEnter != null) { return
     * dataToReEnter; }
     *
     * if (id.equals(0l)) { movie = movieHome.create(title, "", descript, new
     * HashSet(), new HashSet(), new Date(0l), new Date(0l), countries, studio,
     * 0, 0, 0l); } else { movie = movieHome.findByPrimaryKey(id);
     *
     * movie.setTitle(title); movie.setDescription(descript);
     * movie.setCountries(countries); movie.setStudio(studio); }{ // TODO
     * VALIDATION! movie.setBudget(TypeConverter.convertToInt(budget));
     * movie.setWorldCash(TypeConverter.convertToInt(worldCash));
     * movie.setLength(new Long(TypeConverter.convertToInt(length)));
     * movie.setRussianReleaseDate(TypeConverter.convertToDate(russianReleaseDate));
     * movie.setWorldReleaseDate(TypeConverter.convertToDate(worldReleaseDate));
     * movie.setPersons(getPersons()); } String username =
     * actionContext.getUserLogin(); Long uid =
     * EntityUtil.getUserHome().findByLogin(username).getID();
     *
     * String picName = String.format("%d-%s", movie.getId(), ""); //
     * actionContext.getTextParameter(picture file name); String picPath =
     * IOHelper.uploadFile(actionContext, Labels.MOVIE_PICTURE, picName,
     * Config.getMovieImagesDirectory());
     *
     * if(picPath != null) { movie.setPicture(picPath); }
     * JMSUtil.sendLogMessage(Log.INSERT, uid, username, new Date(),
     * Movie.TABLE_NAME, movie.getId(), movie.getTitle());
     * ///////////////////////////////////////
     * /////////////////////////////////////// return
     * XMLHelper.toXMLElement(movie, Labels.getLabel(Labels.VIEW_MOVIE), false,
     * username, new HashMap<String, String>()); } catch (ConversionException
     * ex) { throw new ActionExecutionException("Cannot execute action -
     * CONVERTION ERROR", ex); } catch (SystemException ex) { throw new
     * ActionExecutionException("Cannot execute action", ex); } catch
     * (FinderException ex) { throw new ActionExecutionException("Cannot execute
     * action", ex); } catch (NamingException ex) { throw new
     * ActionExecutionException("Cannot execute action", ex); } catch
     * (CreateException ex) { throw new ActionExecutionException("Cannot execute
     * action", ex); }
     *
     * }
     */
    /*
     * private HashSet getPersons() throws ActionExecutionException {
     *
     * HashSet p = new HashSet(); try { MoviePersonInfo mp; String[] actors =
     * persons_actors.split(";"); for(String str: actors) if (!str.isEmpty()) {
     * mp = new MoviePersonInfo(); mp.id = Long.valueOf(str); mp.type =
     * MoviePersonInfo.ACTOR; p.add(mp); } String[] producers =
     * persons_producers.split(";"); if (producers != null) for(String str:
     * producers) if (!str.isEmpty()) { mp = new MoviePersonInfo(); mp.id =
     * Long.valueOf(str); mp.type = MoviePersonInfo.PRODUCER; p.add(mp); }
     *
     * String[] directors = persons_directors.split(";");
     *
     * for(String str: directors) if (!str.isEmpty()) { mp = new
     * MoviePersonInfo(); mp.id = Long.valueOf(str); mp.type =
     * MoviePersonInfo.DIRECTOR; p.add(mp);} } catch (NumberFormatException ed)
     * { throw new ActionExecutionException("Cannot execute action " +
     * persons_actors+"!"+persons_producers+"!"+persons_directors, ed); } return
     * p; }
     *
     *//*
     * private Element validateMovie() throws SystemException { try { /* String
     * name = actionContext.getTextParameter(PERSON_NAME);
     * if(!StringUtil.isEmpty(name)) { return null; /* }
     *//*
     * Element response = XMLHelper.createElement(Response.RESPONSE); Element e
     * = XMLHelper.addChild(response, Response.ENTITY);
     * e.setAttribute(Response.EDIT, "true");
     *
     * /* XMLHelper.addChild(e,
     * XMLHelper.createHeader(Labels.getLabel(Labels.CREATE_PERSON)));
     * XMLHelper.addChild(e, XMLHelper.createImage("", PERSON_PIC));
     * XMLHelper.addChild(e,
     * XMLHelper.createTextField(Labels.getLabel(Labels.PERSON_NAME), name,
     * PERSON_NAME, Labels.getLabel(Labels.EMPTY_NAME_FIELD_MESSAGE)));
     * XMLHelper.addChild(e,
     * XMLHelper.createTextArea(Labels.getLabel(Labels.PERSON_BIOGRAPHY),
     * actionContext.getTextParameter(PERSON_BIOGRAPHY), PERSON_BIOGRAPHY));
     *
     * XMLHelper.addChild(e,
     * XMLHelper.createButton(Labels.getLabel(Labels.CREATE_PERSON_BUTTON),
     * CreatePersonAction.CREATE_PERSON));
     *//*
     * return null; } catch(Exception e) { //e.printStackTrace(); } return null;
     * }
     *
     *
     * /*private class DefaultMovieFields implements MovieLocal {
     *
     * public Long getId() { return 0l; }
     *
     * public String getTitle() { return ""; }
     *
     * public void setTitle(String title) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public String getPicture() { return ""; }
     *
     * public void setPicture(String pic) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public String getGenres() { return ""; }
     *
     * public void setGenres(HashSet genres) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public String getCountries() { return ""; }
     *
     * public void setCountries(String producingCountries) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Date getRussianReleaseDate() { return new Date(0l); }
     *
     * public void setRussianReleaseDate(Date russianReleaseDate) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Date getWorldReleaseDate() { return new Date(0l); }
     *
     * public void setWorldReleaseDate(Date worldReleaseDate) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public String getStudio() { return ""; }
     *
     * public void setStudio(String studio) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Integer getBudget() { return 0; }
     *
     * public void setBudget(Integer russianCash) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Integer getWorldCash() { return 0; }
     *
     * public void setWorldCash(Integer worldCash) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Long getLength() { return 0l; }
     *
     * public void setLength(Long length) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public String getDescription() { return ""; }
     *
     * public void setDescription(String description) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Double getRating() { return 0d; }
     *
     * public void addRating(Double rating, Long user_id, Date date) throws
     * CreateException { throw new UnsupportedOperationException("Not supported
     * yet."); }
     *
     * public HashSet<MoviePersonInfo> getPersons() { return new HashSet(); }
     *
     * public void setPersons(HashSet<MoviePersonInfo> persons) { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Integer getNvotes() { return 0; }
     *
     * public String stringRepresentation() { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Long addComment(Long user_id, String content, Date date) throws
     * CreateException { throw new UnsupportedOperationException("Not supported
     * yet."); }
     *
     * public void removeComment(Long comment_id) throws RemoveException { throw
     * new UnsupportedOperationException("Not supported yet."); }
     *
     * public void updateComment(Long comment_id, String content, Date date) {
     * throw new UnsupportedOperationException("Not supported yet."); }
     *
     * public LinkedList<Comment> getComments() { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public EJBLocalHome getEJBLocalHome() throws EJBException { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public Object getPrimaryKey() throws EJBException { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public void remove() throws RemoveException, EJBException { throw new
     * UnsupportedOperationException("Not supported yet."); }
     *
     * public boolean isIdentical(EJBLocalObject obj) throws EJBException {
     * throw new UnsupportedOperationException("Not supported yet."); }
     *
     * }
     */



}